home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / SASC_6.0_Disk_7.adf / Source_And_Examples / source / _exit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-30  |  1.4 KB  |  57 lines

  1. /***
  2. *
  3. *          Copyright © 1992 SAS Institute, Inc.
  4. *
  5. * name             __exit -- standard exit function from C program
  6. *
  7. * synopsis         __exit(errcode);
  8. *                  int errcode;          exit error code
  9. *
  10. * description      This function provides a standard exit point from a
  11. *                  C program.  Control is returned to the operating
  12. *                  system under which the program is being executed.
  13. *                  The errcode parameter is sent to the system and has
  14. *                  the following meanings assigned:
  15. *
  16. *                       0 = Normal termination
  17. *                       5 = Warning
  18. *                      10 = Error
  19. *                      20 = Fatal Error
  20. *
  21. ***/
  22.  
  23. #include <fcntl.h>
  24. #include <ios1.h>
  25. #include <dos.h>
  26. #include <stdlib.h>
  27. #include <proto/dos.h>
  28.  
  29. void (*__closefunc)(int);
  30.  
  31. void __exit(errcode)
  32.     int errcode;
  33. {
  34.     struct UFB  *ufb;
  35.     short i;
  36.     char c;
  37.  
  38.  
  39.     for (ufb=__ufbs,i=0; ufb!=NULL; ufb=ufb->ufbnxt,i++) {
  40.         c = ufb->ufbflg;
  41.         if (c && ((c & UFB_NC) == 0))
  42.             (*__closefunc)(i);
  43.         else if (c & UFB_CLO)
  44.         {
  45.            Close(ufb->ufbfh);
  46.         }
  47.     }
  48.  
  49. #ifdef NOBASER
  50. /* this allows DATA=FARONLY functions to call exit, or __exit, */
  51. /* but not XCEXIT. */
  52.      __builtin_geta4();
  53. #endif
  54.  
  55.     _XCEXIT((long) errcode);           /*  Call exit in startup code.  */
  56. }
  57.